1 00:00:00,480 --> 00:00:01,700 Hello and welcome. 2 00:00:01,770 --> 00:00:07,580 In this lecture we will be implementing coalition detection. 3 00:00:08,010 --> 00:00:12,700 So far we have created are pricks. 4 00:00:12,830 --> 00:00:20,070 So at the moment when the ball bounces off the paddle and hits the brick nothing happens. 5 00:00:20,070 --> 00:00:27,750 So what we're going to do is implement some kind of solution detection so that when it does hit the 6 00:00:27,750 --> 00:00:35,380 brick it will break them or it will make them disappear from the campus. 7 00:00:35,400 --> 00:00:44,610 So what we are going to try and do here we are going to implement something to check the centre of the 8 00:00:44,610 --> 00:00:55,330 ball is colliding or touching with any of the bricks kinsell which is going to create some kind of detection 9 00:00:55,330 --> 00:00:55,610 there. 10 00:00:55,620 --> 00:01:04,140 So where by the ball the centre of the ball is touching or colliding with any and giving part of the 11 00:01:04,350 --> 00:01:11,120 bricks again to save a bit of time so you don't have to watch me type the code. 12 00:01:11,400 --> 00:01:19,410 I have already pre written the code here from line 86 to line ninety eight. 13 00:01:19,440 --> 00:01:26,580 So what we got at work done here is create some kind of coalition detection function that will loop 14 00:01:26,880 --> 00:01:35,990 through all the bricks and then compare every single breeks position with the ball's coordinate. 15 00:01:36,000 --> 00:01:47,310 So as each frame or each break is drawn it will compare the position on the X and position on the Y. 16 00:01:47,820 --> 00:01:55,560 All right so create it the function here called coalition detection again Wayne creative functions is 17 00:01:55,590 --> 00:02:06,690 always a good idea to name your function closely related to the function or the activity you want the 18 00:02:06,690 --> 00:02:08,650 function to perform. 19 00:02:08,940 --> 00:02:14,630 So I call this completion detection so it would be detecting coalition. 20 00:02:15,120 --> 00:02:17,420 So I've got a loop here. 21 00:02:17,540 --> 00:02:19,190 So Same here. 22 00:02:19,230 --> 00:02:23,200 You may recognize this look from our previous lectures as well. 23 00:02:23,370 --> 00:02:30,050 So this for loop is saying that it will check for the column the calon value 0. 24 00:02:30,510 --> 00:02:40,610 And if the column is less than the break call long count this here it all had one quick look. 25 00:02:40,620 --> 00:02:42,670 So it will loop to and add 1. 26 00:02:42,850 --> 00:02:48,980 She notices the count is low or has it or is less than the column count. 27 00:02:48,990 --> 00:02:54,660 It had one each time plus bloss means equal out one time elapsed true. 28 00:02:54,900 --> 00:03:03,730 The same applies for the row checks the row zero and f in this less than the brick row count. 29 00:03:03,750 --> 00:03:10,770 Again it adds one each time so he does that each time he goes through the loop so each iteration is 30 00:03:10,790 --> 00:03:12,320 timing all round them. 31 00:03:12,330 --> 00:03:23,500 Do that on to the specified amount or count for the column or row has been met or asked. 32 00:03:23,520 --> 00:03:29,550 I've created a variable here and giving it just the letter B. 33 00:03:29,550 --> 00:03:34,470 What the variable will do. 34 00:03:34,480 --> 00:03:46,830 The variable will be used to store the brick object in every iteration of the loop so the variable will 35 00:03:46,830 --> 00:03:53,470 store the brick object in every loop of the coalition detections So every time it goes through this 36 00:03:53,470 --> 00:03:59,750 floor trying to detect a coalition it will store the information in this variable. 37 00:04:00,490 --> 00:04:04,070 All right so we've given the value of this variable. 38 00:04:04,180 --> 00:04:08,530 He was sort of the breaks and then we've got an array here. 39 00:04:08,610 --> 00:04:10,910 Pass it inside said the array. 40 00:04:10,920 --> 00:04:19,140 We've got a column count and we've got another array here inside that we have the rule variable or count. 41 00:04:19,140 --> 00:04:28,920 So we're saying that if the value of b does state or C distrait status of the B variable is equal to 42 00:04:28,990 --> 00:04:38,950 1 and if the value of the x variable is greater than the B dot X and. 43 00:04:40,340 --> 00:04:42,900 X is less then B. 44 00:04:43,220 --> 00:04:50,360 X bloss 2 with the brick and Y is greater than the brick and is variable B. 45 00:04:51,590 --> 00:04:52,350 And why. 46 00:04:52,490 --> 00:04:59,210 And why is letting them be so if all these values are met the value of DIY. 47 00:04:59,270 --> 00:05:01,970 But it was too deep why mouse. 48 00:05:02,010 --> 00:05:02,660 Why. 49 00:05:02,940 --> 00:05:07,740 And then the value of the status of that will be forced to. 50 00:05:08,240 --> 00:05:17,210 So what this means is that the ex puts it when the exposition of the board is greater than the exposition 51 00:05:17,240 --> 00:05:19,670 of the brick. 52 00:05:19,680 --> 00:05:25,740 It'll draw the brick of the glue will detect the collusion. 53 00:05:25,820 --> 00:05:33,560 So when the exposition of the ball is less than expositional it brick blocks this whiff which is what 54 00:05:33,820 --> 00:05:35,420 I've done here. 55 00:05:35,420 --> 00:05:36,980 Then this happens. 56 00:05:36,980 --> 00:05:44,840 So when the y position of the ball at the y position of the ball is greater than the y position on the 57 00:05:44,840 --> 00:05:45,990 break. 58 00:05:46,370 --> 00:05:48,350 Then this happens. 59 00:05:48,360 --> 00:05:56,510 All right so the y position of the ball when the where position of the ball is less than the position 60 00:05:56,510 --> 00:05:59,920 of the break from the height. 61 00:06:00,410 --> 00:06:05,240 Then there is value because to mine is the. 62 00:06:06,230 --> 00:06:10,390 So here we have also what the State of the state has here. 63 00:06:10,400 --> 00:06:11,130 Checks. 64 00:06:11,300 --> 00:06:18,330 So when the status is set to zero that means the brick would have been hit by the ball. 65 00:06:18,380 --> 00:06:23,870 So we want the brick to disappear by this status's one. 66 00:06:24,080 --> 00:06:30,360 Then the brake is drawn on the screen than is the brick has not been hit yet but whereby this state 67 00:06:30,350 --> 00:06:43,430 or zero it has been hit by the ball and it all disappear from the Cam so we can also track the detection 68 00:06:44,180 --> 00:06:47,720 or the status of the coalition. 69 00:06:47,780 --> 00:06:56,430 So what happens here is that we use the state US property to check for coalition. 70 00:06:56,440 --> 00:06:58,550 The coalition has been detected. 71 00:06:58,730 --> 00:07:03,720 So if the brake is active the status is set to one. 72 00:07:03,980 --> 00:07:08,290 So we'll check to see if the coalition has happened. 73 00:07:08,420 --> 00:07:14,190 If a coalition occurs this status will be set back to zero. 74 00:07:14,480 --> 00:07:20,780 Okay so that means what that means is that the break will not because he's been hit it will not be painted 75 00:07:20,840 --> 00:07:23,000 on drawn on the compass. 76 00:07:23,180 --> 00:07:26,960 So this is how you will of date the coalition. 77 00:07:26,980 --> 00:07:32,340 This is how you would check for the coalition so any break in hit value set to zero. 78 00:07:32,360 --> 00:07:36,530 It doesn't get drawn again on the compass when the loop goes round. 79 00:07:36,650 --> 00:07:39,410 It is excluded from the loop. 80 00:07:39,980 --> 00:07:43,190 Alright that's it for this leg shot in this leg. 81 00:07:43,180 --> 00:07:49,310 Sure we create a function to do some collision detection. 82 00:07:49,310 --> 00:07:59,900 We all saw torched briefly on how to make the balls or the breaks disappear from the screen. 83 00:07:59,900 --> 00:08:10,610 Once they have been hit with the ball we all saw some kind of tracking to check for the status of the 84 00:08:10,700 --> 00:08:15,330 coalition so if a break has been hit the state is set to zero. 85 00:08:15,350 --> 00:08:23,360 So when the loop cause is not painted or create or drawn game on become mass so when the brick is active 86 00:08:23,680 --> 00:08:29,000 the status is one and then it can be created or drawn on the compass. 87 00:08:29,210 --> 00:08:30,980 Thank you so much for watching. 88 00:08:30,980 --> 00:08:31,800 Bye for now.